<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 定义数组
        var array1 = ['a','a','a','b','b','c','c','c','c','d','d','d','d'];
        // 首先把去重把这些放进一个数组中
        function construct (arr) {
            // 定义一个新数组存放去重后的数组
            var array = [];
            console.log(arr.length);
            for (var i = 1 ; i < arr.length ; i++) {
                // 如果新数组中没有这个元素，则把这个元素放进去
                if (array.indexOf(arr[i]) == -1) {
                    array.push(arr[i]);
                }
            }
            console.log(array);
            // 然后统计重复出现的次数
            var countArr = [];
            for (var j = 0; j < array.length ; j++) {
                countArr[j] = 0;
            }
            for (var k = 0; k < array.length; k++) {
                for(var m = 0; m < arr.length ; m++) {
                    if (array[k] == arr[m]) {
                        countArr[k]++;
                    }
                }
            }
            // countArr = countArr.join(",");


            var ob = new Object();
            ob.a = countArr[0];
            ob.b = countArr[1];
            ob.c = countArr[2];
            ob.d = countArr[3];
            console.log(ob);
        }
        construct(array1);
    </script>
</head>
<body>
    18.  数组转对象；

    ```js

    ['a','a','a','b','b','c','c','c','c','d','d','d','d'] 

    ---> 

    {

        a: 3,

        b: 2,

        c: 4,

        d: 4

    }

    ```
</body>
</html>